﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Teein.Proxy.Bot.Model;
using MongoDB.Driver;

namespace Teein.Proxy.Bot.DAL
{
    public class ProxyDAL : SQLHelper,IDAL<ProxyInfo>
    {
        public bool Insert(ProxyInfo model)
        {
           return SQLHelper.Insert<ProxyInfo>(model);
        }

        public bool Update(ProxyInfo model)
        {
            UpdateDocument ud = new UpdateDocument();
            ud.Add("IP", model.IP);
            ud.Add("IsUse", model.IsUse);
            ud.Add("Port", model.Port);
            ud.Add("Ping", model.Ping);
            ud.Add("State", model.State);
            ud.Add("LastTime", model.LastTime);
            return SQLHelper.Update<ProxyInfo>(new QueryDocument("_id", model.PID), ud);
        }

        public bool Delete(ProxyInfo model)
        {
            return SQLHelper.Delete<ProxyInfo>(new QueryDocument("_id", model.PID));
        }

        public bool Delete(MongoDB.Driver.IMongoQuery mq)
        {
            return SQLHelper.Delete<ProxyInfo>(mq);
        }

        public ProxyInfo FindOne(MongoDB.Driver.IMongoQuery mq)
        {
            return SQLHelper.FindOne<ProxyInfo>(mq);
        }

        public IList<ProxyInfo> Find(MongoDB.Driver.IMongoQuery mq)
        {
            return SQLHelper.Find<ProxyInfo>(mq);
        }
    }
}
